home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Edit List and Spin / EnvironmentVars / EnvironmentVars.cs next >
Encoding:
Text File  |  2001-01-15  |  1.8 KB  |  56 lines

  1. //----------------------------------------------
  2. // EnvironmentVars.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------
  4. using System;
  5. using System.Collections;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8.  
  9. class EnvironmentVars: Form
  10. {
  11.      Label label;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new EnvironmentVars());
  16.      }
  17.      public EnvironmentVars()
  18.      {
  19.           Text = "Environment Variables";
  20.  
  21.                // Create Label control.
  22.  
  23.           label = new Label();
  24.           label.Parent   = this;
  25.           label.Anchor   = AnchorStyles.Left | AnchorStyles.Right;
  26.           label.Location = new Point(Font.Height, Font.Height);
  27.           label.Size     = new Size(ClientSize.Width - 2 * Font.Height, 
  28.                                     Font.Height);
  29.  
  30.                // Create ListBox control.
  31.  
  32.           ListBox listbox  = new ListBox();
  33.           listbox.Parent   = this;
  34.           listbox.Location = new Point(Font.Height, 3 * Font.Height);
  35.           listbox.Size     = new Size(12 * Font.Height, 8 * Font.Height);
  36.           listbox.Sorted   = true;
  37.           listbox.SelectedIndexChanged += 
  38.                          new EventHandler(ListBoxOnSelectedIndexChanged);
  39.  
  40.                // Set environment strings in ListBox control.
  41.  
  42.           IDictionary dict = Environment.GetEnvironmentVariables();
  43.           string[]    astr = new String[dict.Keys.Count];
  44.  
  45.           dict.Keys.CopyTo(astr, 0);
  46.           listbox.Items.AddRange(astr);
  47.           listbox.SelectedIndex = 0;
  48.      }
  49.      void ListBoxOnSelectedIndexChanged(object obj, EventArgs ea)
  50.      {
  51.           ListBox listbox = (ListBox) obj;
  52.           string  strItem = (string) listbox.SelectedItem;
  53.  
  54.           label.Text = Environment.GetEnvironmentVariable(strItem);
  55.      }
  56. }